package com.tanhua.dubbo.api.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.domain.db.User;
import com.tanhua.dubbo.api.UserApi;
import com.tanhua.dubbo.mapper.UserMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class UserApiImpl implements UserApi {

    @Autowired
    private UserMapper userMapper;

    @Override
    public Long save(User user) {
        userMapper.insert(user);
        return user.getId();
    }

    @Override
    public User findByMobile(String mobile) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("mobile", mobile);
        return userMapper.selectOne(wrapper);
    }

    @Override
    public User findById(Long lid){
        return userMapper.selectById(lid);
    }

    @Override
    public void updateMobile(User user) {
        QueryWrapper<User> query = new QueryWrapper<>();
        query.eq("id", user.getId());
        userMapper.update(user, query);
    }

    @Override
    public List<User> findAll() {
        QueryWrapper<User> query = new QueryWrapper<>();
        query.le("id", 80);
        return userMapper.selectList(query);
    }
}
